package com.hjm.admin.moule.view.adapter;

import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hjm.admin.moule.R;
import com.hjm.admin.moule.widget.page.TxtChapter;

import java.util.List;

public class ReadCategoryAdapter extends BaseQuickAdapter<TxtChapter, BaseViewHolder> {
    public ReadCategoryAdapter(@Nullable List<TxtChapter> data) {
        super(R.layout.item_category, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TxtChapter item) {
        Drawable drawable;
        if (item.getLink() == null)
            drawable = ContextCompat.getDrawable(mContext, R.drawable.selector_category_load);
        else {
            if (item.getBookId() != null)
                drawable = ContextCompat.getDrawable(mContext, R.drawable.selector_category_load);
            else
                drawable = ContextCompat.getDrawable(mContext, R.drawable.selector_category_unload);
        }
        TextView category_tv_chapter = helper.getView(R.id.category_tv_chapter);
        category_tv_chapter.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
        category_tv_chapter.setSelected(item.isSelect());
        category_tv_chapter.setText(item.getTitle());
        if (item.isSelect())
            category_tv_chapter.setTextColor(ContextCompat.getColor(mContext, R.color.color_ec4a48));
        else
            category_tv_chapter.setTextColor(ContextCompat.getColor(mContext, R.color.black));
    }
}
